#!/usr/bin/python
'''
/*
 * This computer program is the confidential information and proprietary trade
 * secret of VistaraIT LLC.  Possessions and use of this program must  conform
 * strictly to the license agreement between the user and VistaraIT LLC.,  and
 * receipt or possession does not convey any rights to divulge, reproduce,  or
 * allow others to use this program without specific written authorization  of
 * VistaraIT LLC.
 * 
 * Copyright (c) 2014 VistaraIT, Inc. All rights reserved.
 */
'''

import datetime, os
from commons import executeCommand
import applicationproperties as properties

INFO = 'INFO'
WARN = 'WARN'
ERROR = 'ERROR'
DEBUG = 'DEBUG'

def logMessage(sev, process, message):
    now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    if not os.path.exists(properties.APPLIANCE_LOG_FILE):
        cmd = "/usr/bin/sudo /bin/touch " + properties.APPLIANCE_LOG_FILE
        executeCommand(cmd, [], True)
        cmd = "/usr/bin/sudo /bin/chown admin.admin " + properties.APPLIANCE_LOG_FILE
        executeCommand(cmd, [], True)
    cmd = "echo \"" + now + " : " +  sev + " : " + process +" : " + message + "\" >> " + properties.APPLIANCE_LOG_FILE + " 2>/dev/null";
    return executeCommand(cmd,[],True)[0] == 0

def logUpdates(sev, process, message):
    now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    if not os.path.exists(properties.UPGRADES_LOGFILE):
        cmd = "/usr/bin/sudo /bin/touch " + properties.UPGRADES_LOGFILE
        executeCommand(cmd, [], True)
        cmd = "/usr/bin/sudo /bin/chown admin.admin " + properties.UPGRADES_LOGFILE
        executeCommand(cmd, [], True)
    cmd = "echo \"" + now + " : " +  sev + " : " + process +" : " + message + "\" >> " + properties.UPGRADES_LOGFILE + " 2>/dev/null";
    return executeCommand(cmd,[],True)[0] == 0

def logDebugMsgs(sev, process, message):
    cmd = "echo \"" + message + "\" >> " + properties.DEBUG_LOG_FILE + " 2>/dev/null";
    return executeCommand(cmd,[],True)[0] == 0
